<template>
  <div class="details-content">
    <div class="button-content">
      <div class="top-button-box">
        <el-button type="primary" @click="submitForm" size="mini" v-if="canSave">保 存</el-button>
        <el-button type="primary" @click="refresh" size="mini">刷新</el-button>
      </div>
    </div>
    <el-form ref="form" :model="form" :rules="rules" label-width="110px" class="main-form">

      <el-row :xs="24" :sm="24" :md="24" :lg="24" :xl="24">

        <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="6">
          <el-form-item label="单据名称" prop="ctMeetingPlace">
            <el-input v-model="form.ctMeetingPlace" placeholder="请输入单据名称" :readonly="!canSave"/>
          </el-form-item>
        </el-col>



<!--        <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="6">-->
<!--          <el-form-item label="出席率" prop="ctAttendanceRate">-->
<!--            <el-input v-model="form.ctAttendanceRate" placeholder="自动计算" disabled/>-->
<!--          </el-form-item>-->
<!--        </el-col>-->

        <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="6">
          <el-form-item label="在线用户" prop="amPatrolNumber">
            <el-input
              v-model="form.amPatrolNumber"
              placeholder="请输入在线用户"
              type="number"
              :readonly="!canSave"
            />
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="6">
          <el-form-item label="单据浏览次数" prop="amAuditNumber">
            <el-input
              v-model="form.amAuditNumber"
              placeholder="请输入单据浏览次数"
              type="number"
              :readonly="!canSave"
            />
          </el-form-item>
        </el-col>

        <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
          <el-form-item label="备注说明" prop="ctMark">
            <el-input
              v-model="form.ctMark"
              type="textarea"
              :rows="3"
              placeholder="请输入备注说明"
              :readonly="!canSave"
            />
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="6">
          <el-form-item label="检阅通知" prop="ctReviewNotice">
            <el-switch
              v-model="form.ctReviewNotice"
              active-value="1"
              inactive-value="0"
              :disabled="!canSave"
            ></el-switch>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="6">
          <el-form-item label="签发通知" prop="ctIssuanceNotice">
            <el-switch
              v-model="form.ctIssuanceNotice"
              active-value="1"
              inactive-value="0"
              :disabled="!canSave"
            ></el-switch>
          </el-form-item>
        </el-col>
      </el-row>

      <create-info
        :ct-create-user="form.ctCreateUser"
        :dt-create-date="form.dtCreateDate"
        :ct-update-user="form.ctUpdateUser"
        :dt-update-date="form.dtUpdateDate"
        :update-create-info="form.updateCreateInfo"
      ></create-info>
    </el-form>
    <div class="button-content">
      <div class="bottom-button-box">
        <el-button type="primary" @click="submitForm" size="mini" v-if="canSave">保 存</el-button>
        <el-button type="primary" @click="refresh" size="mini">刷新</el-button>
      </div>
    </div>

  </div>
</template>


<script>
  import {
    listTDwMeetingManagement,
    getTDwMeetingManagement,
    delTDwMeetingManagement,
    addTDwMeetingManagement,
    updateTDwMeetingManagement,
    exportTDwMeetingManagement,
  } from '@/api/masterRecord/TDwMeetingManagement'
  import Editor from '@/components/Editor'

  import { getBaseFunction } from '@/api/mis/function'

  import CreateInfo from '@/components/SpsPublic/CreateInfo/CreateInfo'
  import { getFunNo } from '@/utils/party'

  import store from '@/store/index'


  export default {
    name: 'TDwMeetingManagement',
    meetList:false,

    components: {
      Editor
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 测试功能表格数据
        managementList: [],
        // 弹出层标题
        title: '',
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          ctId: null,
          ctCode: null,
          ctType: null,
          ctName: null,
          ctCurStepno: null,
          ctHisStepno: null,
          ctCreateDept: null,
          ctCreateUser: null,
          dtCreateDate: null,
          ctSendP: null,
          ctInceptP: null,
          ctInceptType: null,
          ctCodeP1: null,
          ctCodeP2: null,
          ctEnd: null,
          ctMark: null,
          ctCodeIso: null,
          ctFunNo: null,
          ctTaskId: null,
          ctUpdateUser: null,
          dtUpdateDate: null,
          ctState: null,
          ctBranch: null,
          dtDate: null,
          ctBussType: null,
          ctMeetingPlace: null,
          ctHostName: null,
          ctHostCode: null,
          ctRecorderName: null,
          ctRecorderCode: null,
          amShouldNumber: null,
          amActualNumber: null,
          ctAttendanceRate: null,
          ctParticipateName: null,
          ctParticipateCode: null,
          ctAbsentName: null,
          ctAbsentCode: null,
          ctAbsentReason: null,
          ctOtherPersonnel: null,
          amOtherNumber: null,
          amPatrolNumber: null,
          amAuditNumber: null,
          ctMeetingIssue: null,
          ctMeetingContent: null,
          amClickVolume: null,
          ctHuck: null,
          ctIfMatter: null,
          ctIfSigned: null,
          ctIsOpen: null,
          ctReviewNotice: null,
          ctIssuanceNotice: null,
          ctOther1: null,
          ctOther2: null,
          ctOther3: null,
          ctOther4: null,
          ctOther5: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          ctId: [
            { required: true, message: '单据唯一编号不能为空', trigger: 'blur' }
          ]
        },

        // 可否保存和表单控件disable标识
        canSave: false,
        funNo: getFunNo(this.$route),
        singleStore: null,
        subSingleStore: null,
        openTreeTransfer: false,
       // ifPartyCommittee: store.state.user.branchInfo.ifPartyCommittee == '1',
      }
    },
    created() {
      //创建的时候不要再这里写 this.getRecord() 等， 否则初始化forminit不好用，切记。
      //直接再mounted中写！！！！！
      getBaseFunction(this.subFunNo).then((response) => {
        this.meetList = response.data.amMeetingDisplayType
      })
    //  this.getList()
    },

    mounted() {
      console.log(this.canSave)
      this.singleStore = store.getters.singleStore['main' + this.funNo]
      this.subSingleStore = this.singleStore.subSingleStore['sub' + this.subFunNo]
      this.getRecord()
    },
    methods: {
      refresh() {
        this.masterRefresh()
      },

      /** 查询测试功能列表 */
     /* getList() {
        this.loading = true
        listManagement(this.queryParams).then(response => {
          this.managementList = response.rows
          this.total = response.total
          this.loading = false
        })
      },*/
      // 取消按钮
      cancel() {
        this.open = false
        this.reset()
      },
      // 表单重置
      reset() {
        this.form = {
          ctId: null,
          ctCode: null,
          ctType: null,
          ctName: null,
          ctCurStepno: null,
          ctHisStepno: null,
          ctCreateDept: null,
          ctCreateUser: null,
          dtCreateDate: null,
          ctSendP: null,
          ctInceptP: null,
          ctInceptType: null,
          ctCodeP1: null,
          ctCodeP2: null,
          ctEnd: null,
          ctMark: null,
          ctCodeIso: null,
          ctFunNo: null,
          ctTaskId: null,
          ctUpdateUser: null,
          dtUpdateDate: null,
          ctState: null,
          ctBranch: null,
          dtDate: null,
          ctBussType: null,
          ctMeetingPlace: null,
          ctHostName: null,
          ctHostCode: null,
          ctRecorderName: null,
          ctRecorderCode: null,
          amShouldNumber: null,
          amActualNumber: null,
          ctAttendanceRate: null,
          ctParticipateName: null,
          ctParticipateCode: null,
          ctAbsentName: null,
          ctAbsentCode: null,
          ctAbsentReason: null,
          ctOtherPersonnel: null,
          amOtherNumber: null,
          amPatrolNumber: null,
          amAuditNumber: null,
          ctMeetingIssue: null,
          ctMeetingContent: null,
          amClickVolume: null,
          ctHuck: null,
          ctIfMatter: null,
          ctIfSigned: null,
          ctIsOpen: null,
          ctReviewNotice: null,
          ctIssuanceNotice: null,
          ctOther1: null,
          ctOther2: null,
          ctOther3: null,
          ctOther4: null,
          ctOther5: null
        }
        this.resetForm('form')
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1
        this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm('queryForm')
        this.handleQuery()
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.ctId)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset()
        this.open = true
        this.title = '添加测试功能'
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset()
        const ctId = row.ctId || this.ids
        getTDwMeetingManagement(ctId).then(response => {
          this.form = response.data
          this.open = true
          this.title = '修改测试功能'
        })
      },

      getRecord() {
        if (this.singleStore.handleType != 'add' && this.bussId) {
          getTDwMeetingManagement(this.bussId).then((response) => {
            if (response.data) {
              this.$nextTick(() => {
                this.form = response.data
             /*   this.form.ctParticipateOldList = [
                  ...this.form.ctParticipateNowList
                ]
                this.form.meetOldList = [...this.form.meetNowList]*/
                this.form.subFunNo = this.subFunNo
                this.form.funNo = this.funNo
                this.form.updateCreateInfo = true
              /*  if (this.form.ctParticipateNowList.length == 0) {
                  this.$set(this.form, 'ctParticipateName', '')
                } else {
                  this.$set(this.form, 'ctParticipateName', '已选择')
                }
                if (this.form.meetNowList.length > 0) {
                  this.$set(this.form, 'ctMeetingContent', '已添加')
                  if (!this.meetList) {
                    this.getMycontent()
                  }
                } else {
                  this.$set(this.form, 'ctMeetingContent', '')
                  this.$set(this.form, 'myContent', '')
                }*/
                store.dispatch('setStoreForm', this.form)
              })
            }
          })
        } else if (this.singleStore.handleType == 'add') {
          // 新增
          this.formInit()
          store.dispatch('setStoreForm', this.form)
        }
      },

      /** 提交按钮 */
      submitForm() {
        this.$refs['form'].validate(valid => {
          if (valid) {
            if (this.form.ctId != null) {
              updateTDwMeetingManagement(this.form).then(response => {
                this.msgSuccess('修改成功')
                this.open = false
                this.getList()
              })
            } else {
              addTDwMeetingManagement(this.form).then(response => {
                this.msgSuccess('新增成功')
                this.open = false
                this.getList()
              })
            }
          }
        })
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ctIds = row.ctId || this.ids
        this.$confirm('是否确认删除测试功能编号为"' + ctIds + '"的数据项?', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function() {
          return delManagement(ctIds)
        }).then(() => {
          this.getList()
          this.msgSuccess('删除成功')
        })
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams
        this.$confirm('是否确认导出所有测试功能数据项?', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function() {
          return exportManagement(queryParams)
        }).then(response => {
          this.download(response.msg)
        })
      }
    },
  }
</script>
<style>
  .main-form .vue-treeselect__control {
    width: 100%;
  }

  .ql-toolbar.ql-snow {
    border: none;
  }
</style>
